﻿@{
    ViewBag.Title = "SimulateForm";
    Layout = "~/Views/Shared/_Form.cshtml";
}

@Html.Partial("_YibaoCommonView")
<div class="panel panel-default" id="dvpatInfo" style="margin-top:10px;margin-left:10px;margin-right: 10px;">
    <div class="panel-heading navb-bg" style="height:25px;line-height: 25px;">
        住院信息
    </div>
    <div style="height:auto;">
        <table class="form">
            <tr>
                <th class="formTitle">住院号：</th>
                <td class="formValue"><label id="zyh"></label></td>
                @*<th class="formTitle">入院日期：</th>
                    <td class="formValue"><label id=""></label></td>*@
                <th class="formTitle">个人编号：</th>
                <td class="formValue"><label id="sbbh"></label></td>
                <th class="formTitle">分中心编号：</th>
                <td class="formValue"><label id="fzxbh"></label></td>
            </tr>
            <tr>
                <th class="formTitle">支付类别：</th>
                <td class="formValue"><label id="zhifuleibie"></label></td>
                <th class="formTitle">社保办法：</th>
                <td class="formValue"><label id="sbbf"></label></td>
                <th class="formTitle">费用总额：</th>
                <td class="formValue"><label id="hisfyze"></label></td>
            </tr>
        </table>
    </div>
</div>

<!-- 重庆医保展示 -->
<div id="divCQYbFee" class="panel panel-default" style="display:none;margin-top:10px;margin-left:10px;margin-right: 10px;">
	<div class="panel-heading navb-bg" style="height:13px;">
		费用信息
	</div>
	<div style="height:auto;">
        <table class="form">
            <tr>
                <th class="formTitle">费用总额：</th>
                <td class="formValue">￥<label id="cq_fyze">0.00</label></td>
                <th class="formTitle">现金支付合计：</th>
                <td class="formValue">￥<label id="cq_xjzf">0.00</label></td>
                <th class="formTitle">非医保现金计费：</th>
                <td class="formValue">￥<label id="zf_xjzf">0.00</label></td>

            </tr>
            <tr>
                <th class="formTitle">医保现金计费：</th>
                <td class="formValue">￥<label id="yb_xjzf">0.00</label></td>
                <th class="formTitle">统筹支付：</th>
                <td class="formValue">￥<label id="cq_tczf">0.00</label></td>
                <th class="formTitle">公务员补助：</th>
                <td class="formValue">￥<label id="cq_gwybz">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">账户支付：</th>
                <td class="formValue">￥<label id="cq_zhzf">0.00</label></td>
                <th class="formTitle">单病种医疗垫支：</th>
                <td class="formValue">￥<label id="dbzddyljgdz">0.00</label></td>

                <th class="formTitle">大额理赔支付：</th>
                <td class="formValue">￥<label id="cq_delp">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">企业医疗保险支出：</th>
                <td class="formValue">￥<label id="cq_qybxzc">0.00</label></td>
                <th class="formTitle">居民大病支出：</th>
                <td class="formValue">￥<label id="cq_jmdbzc">0.00</label></td>
                <th class="formTitle">医疗救助基金支出：</th>
                <td class="formValue">￥<label id="cq_mzbz">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">账户共济支付：</th>
                <td class="formValue">￥<label id="cq_zhgjzf">0.00</label></td>
                <th class="formTitle">其他：</th>
                <td class="formValue">￥<label id="cq_qt">0.00</label></td>
                <th class="formTitle">符合政策范围金额：</th>
                <td class="formValue">￥<label id="cq_hszjfw">0.00</label></td>
            </tr>
            <tr>
                <th class="formTitle">实际支付起付线：</th>
                <td class="formValue">￥<label id="cq_zfqfx">0.00</label></td>
            </tr>
        </table>
	</div>
</div>
@Html.Partial("_YibaoCommonView")

<script type="text/javascript">
    var zyh = $.request("zyh"); 
    var ryrq = $.request("ryrq"); 
    var hisfyze = $.request("hisfyze");
    var isYbjyjz = $.request("isYbjyjz") === 'true';
    var isXnhjyjz = $.request("isXnhjyjz") === 'true';
    var medicalInsurance = $.request("medicalInsurance");
    $(function () {
    	if (medicalInsurance == "chongqing") {
		    $('#divCQYbFee').show();
		    $('#dvpatInfo').remove();
    	}
        init();
    });

    function init() {
        if (isYbjyjz) {
            if (medicalInsurance == "chongqing") {
            	setTimeout(function(){ 
                    $.loading(true, '正在进行明细上传，请稍后...');
                    setTimeout(function() {
                            CQmxsc(function(mxxx) {
                                $.loading(true, '正在进行模拟结算，请稍后...');
                                setTimeout(function () {
                                    CQybjs(mxxx);
                                        //CQsppd(mxxx,
                                        //    function() {
                                        //        setTimeout(function() {
                                        //                $.loading(true, '正在进行模拟结算，请稍后...');
                                        //                CQybjs(mxxx);
                                        //            },
                                        //            50);
                                        //    });
                                    },
                                    50);

                            });
                        },
                        50);

                    },
		            50)};
            
        }
    }

    var patInfo;
    function initPatientInfo(data) {
        patInfo = data;
        $('#zyh').html(data.zyh);
        $('#sbbh').html(data.sbbh);
        $('#fzxbh').html(data.fzxbh);
        $('#zhifuleibie').html(data.zhifuleibie);
        $('#sbbf').html(data.sbbf);
        $('#hisfyze').html(parseFloat(hisfyze).toFixed(2));
    }
    //审批判定，调用22接口查看是否有未审批数据
    function CQsppd(mxxx, funcSuccCallback) {
        var parameter1 = { "zyh": zyh, "splx": "1", "rq": $.getDate({ date: ryrq }), "xzlb": "1" };
        var parameter2 = { "zyh": zyh, "splx": "2", "rq": $.getDate({ date: ryrq }), "xzlb": "1" };
        var spGsfReturn;
        var spBdbReturn;
        $.ajax({
            type: "POST",
            url: "http://127.0.0.1:22222/api/CQYiBao/GetApprovalXm",
            data: parameter1,
            dataType: "json",
            async: false,
            success: function (data) {
                spGsfReturn = eval('(' + data + ')');
            }
        });
        $.ajax({
            type: "POST",
            url: "http://127.0.0.1:22222/api/CQYiBao/GetApprovalXm",
            data: parameter2,
            dataType: "json",
            async: false,
            success: function (data) {
                spBdbReturn = eval('(' + data + ')');
            }
        });
        if (!!spGsfReturn && !!spBdbReturn && spGsfReturn.Code === "1" && spBdbReturn.Code === "1") {
            if (!!spGsfReturn.Data && spGsfReturn.Data.cfmxlshList.length > 0) {
                $.loading(false);
                $.modalAlert("患者有高收费项目还未审批，请联系医保办审批后再次结算！", 'error');
                return;
            }
            if (!!spGsfReturn.Data && spBdbReturn.Data.cfmxlshList.length > 0) {
                $.loading(false);
                $.modalAlert("患者有白蛋白项目还未审批，请联系医保办审批后再次结算！", 'error');
                return;
            }
        } else {
            $.loading(false);
            $.modalAlert("调用医保22接口失败", 'error');
            return;
        }
        if (funcSuccCallback) {
            funcSuccCallback(mxxx);
        }
    }


</script>
<script type="text/javascript">
    //医保逻辑

    //获取结算患者 患者信息
    function funcGetSettPatientInfo(funcSuccCallback) {
        $.najax({
            url: '/HospitalizationManage/DischargeSettle/GetInpatientSettYbPatInfo?zyh=' + zyh,
            loadingtext: "正在请求患者出院信息，请稍后...",
            type: 'POST',
            success: function (ajaxResp) {
                initPatientInfo(ajaxResp.data);
                //
                if (funcSuccCallback) {
                    setTimeout(function () {
                        funcSuccCallback(ajaxResp.data);
                    }, 50);
                }
            }
        });
    }
	//重庆医保逻辑相关
    function CQmxsc(funcSuccCallback) {
	    var n = 1;
	    var ybzje = 0.00;
	    var succTimes = 0;
	    var mdtrt_id;
	    var med_type;
	    var mdtrt_cert_type;
	    var mdtrt_cert_no;
	    var mxnum = 0;
	    var isuccer = true;//明细上传是否成功

	    $.ajax({
	        type: "POST",
	        url: "/PatientManage/HospiterRes/GetCQjzdjInfo",
	        data: { zyh: zyh },
	        dataType: "json",
	        cache: false,
	        async: false,
	        success: function (payoptype) {
	            if (payoptype) {
	                //每次重新上传，先把以前上传的，但未结算的处方退掉
	                payoptype.feedetl_sn = "0000";
	                $.ajax({
	                    type: "POST",
	                    url: "http://127.0.0.1:33333/api/YiBao/HospitaUpDscginfo_2302",
	                    data: payoptype,
	                    dataType: "json",
	                    async: false,
	                    success: function (data) {
	                    }
	                });
	                payoptype.uploadCount = "100";
	                $.najax({
	                    type: "GET",
	                    data: {
	                        mzzyh: zyh, cflx: '2'
	                    },
	                    url: "/HospitalizationManage/DischargeSettle/GetNogjybdm",
	                    dataType: "json",
	                    async: false,
	                    loading: false,
	                    success: function (ajaxResp) {
	                        var xmmc = ajaxResp.xmmc;
	                        if (xmmc) {
	                            $.loading(false);
	                            isuccer = false;
	                            $.modalAlert(xmmc + "未对照国家医保编码!请核实", 'error');
	                            return;
	                        }
	                        else {
	                            $.ajax({
	                                type: "POST",
	                                url: "http://127.0.0.1:33333/api/YiBao/HospitaFeedetail_2301",
	                                data: payoptype,
	                                dataType: "json",
	                                async: false,
	                                success: function (data) {
	                                    var upDataReturn = eval('(' + data + ')');
	                                    if (upDataReturn.infcode == "0") {
	                                        $.najax({
	                                            type: "GET",
	                                            data: {
	                                                mzzyh: zyh
	                                            },
	                                            url: "/HospitalizationManage/DischargeSettle/GetCQAlreadyUploadFeeDetails",
	                                            dataType: "json",
	                                            async: false,
	                                            loading: false,
	                                            success: function (ajaxResp) {
	                                                if (ajaxResp) {
	                                                    payoptype.medfee_sumamt = ajaxResp.ybzje;
	                                                    funcSuccCallback(payoptype);
	                                                }

	                                            }
	                                        });
	                                    }
	                                    else {
	                                        $.loading(false);
	                                        isuccer = false;
	                                        $.modalAlert("明细上传失败：" + upDataReturn.err_msg, 'error');
	                                        return;
	                                    }

	                                }
	                            });
	                        }

	                    }
	                });
	               
	            }
	            else {
	                $.loading(false);
	                $.modalAlert("获取住院就诊登记失败", 'error');
	                return;
	            }
	           
	        }

	    });
	    //$.loading(false);
	    //if (funcSuccCallback && isuccer) {
	    //    setTimeout(function () {
	    //        var mxxx = { ybzje: ybzje, mdtrt_id: mdtrt_id, med_type: med_type, mdtrt_cert_type: mdtrt_cert_type, mdtrt_cert_no: mdtrt_cert_no };
	    //        funcSuccCallback(mxxx);
	    //    }, 50);
	    //}
    }
    function CQybjs(predata) {
        $.ajax({
            type: "GET",
            url: "/HospitalizationManage/DischargeSettle/GetCQJsPatInfo?zyh=" +zyh,
            dataType: "json",
            async: false,
            success: function (ajaxresp) {
                if (ajaxresp) {
                    predata.dscgTime = ajaxresp.cyrq;
                }
            }
        });
        predata.psn_setlway = "01";
        predata.mid_setl_flag = "0";
        predata.acct_used_flag = "1";
        predata.mdtrt_cert_type = "03";
        var ybjsSettReturn;
        var ybyjsxx;
	    $.ajax({
		    type: "POST",
		    url: "http://127.0.0.1:33333/api/YiBao/HospitaSettlement_2303",
		    data: predata,
		    dataType: "json",
		    async: false,
		    success: function (data) {
			    ybjsSettReturn = eval('(' + data + ')');
		    }
	    });
	    if (ybjsSettReturn) {
            if (ybjsSettReturn.infcode == "0") {
                ybyjsxx = ybjsSettReturn.output.setlinfo;
	            var ybjyFeeReturn = ybjsSettReturn.output.setlinfo;
	            var mzjzje = 0.000;//民政救助金额
	            var xjzfje = 0.000;//医保的现金支付金额
	            var zfxjzf = 0.000;//非医保现金支付金额

	            //医保的现金支付金额
	            xjzfje = ovpraseFloat(ybjyFeeReturn.psn_cash_pay);
	            //非医保现金金额
	            zfxjzf = ovpraseFloat(hisfyze) -
			        ovpraseFloat(predata.medfee_sumamt);
	            //计算现金支付
	            var calc_xjzf = ovpraseFloat(ybjyFeeReturn.psn_cash_pay) +
			        ovpraseFloat(hisfyze) -
			        ovpraseFloat(predata.medfee_sumamt);
	            ybjyFeeReturn.calc_xjzf = calc_xjzf;

	            orglxjzfys = ovpraseFloat(ybjyFeeReturn.calc_xjzf);
	            xjzfys = orglxjzfys;    //有折扣时会不等

	            mzjzje = ovpraseFloat(ybjyFeeReturn.maf_pay);

	            !!hisfyze && $('#cq_fyze').html(ovpraseFloat(hisfyze).toFixed(2));
	            !!ybjyFeeReturn.calc_xjzf && $('#cq_xjzf').html(ovpraseFloat(ybjyFeeReturn.calc_xjzf).toFixed(2));//总现金支付
	            !!zfxjzf && $('#zf_xjzf').html(zfxjzf.toFixed(2));//非医保现金支付
	            !!xjzfje && $('#yb_xjzf').html(xjzfje.toFixed(2));//医保现金支付
	            !!ybjyFeeReturn.acct_pay && $('#cq_zhzf').html(ovpraseFloat(ybjyFeeReturn.acct_pay).toFixed(2));
	            !!ybjyFeeReturn.hifp_pay && $('#cq_tczf').html((ovpraseFloat(ybjyFeeReturn.hifp_pay)));
	            !!ybjyFeeReturn.hifob_pay && $('#cq_delp').html(ovpraseFloat(ybjyFeeReturn.hifob_pay).toFixed(2));
	            !!ybjyFeeReturn.cvlserv_pay && $('#cq_gwybz').html(ovpraseFloat(ybjyFeeReturn.cvlserv_pay).toFixed(2));
	            !!ybjyFeeReturn.maf_pay && $('#cq_mzbz').html(mzjzje);

	            !!ybjyFeeReturn.hosp_part_amt && $('#dbzddyljgdz').html((ovpraseFloat(ybjyFeeReturn.hosp_part_amt)));

	            !!ybjyFeeReturn.hifes_pay && $('#cq_qybxzc').html(ovpraseFloat(ybjyFeeReturn.hifes_pay).toFixed(2));
	            !!ybjyFeeReturn.hifmi_pay && $('#cq_jmdbzc').html(ovpraseFloat(ybjyFeeReturn.hifmi_pay).toFixed(2));
	            !!ybjyFeeReturn.oth_pay && $('#cq_qt').html(ovpraseFloat(ybjyFeeReturn.oth_pay).toFixed(2));
	            !!ybjyFeeReturn.acct_mulaid_pay && $('#cq_zhgjzf').html(ovpraseFloat(ybjyFeeReturn.acct_mulaid_pay).toFixed(2));

	            !!ybjyFeeReturn.inscp_scp_amt && $('#cq_hszjfw').html(ovpraseFloat(ybjyFeeReturn.inscp_scp_amt).toFixed(2));
                !!ybjyFeeReturn.act_pay_dedc && $('#cq_zfqfx').html(ovpraseFloat(ybjyFeeReturn.act_pay_dedc).toFixed(2));

                //预结算落地
                ybyjsxx.zyh = zyh;
                YByjsld(ybyjsxx);
		    } else {
			    $.loading(false);
			    $.modalAlert("医保预结算失败:"+ybjsSettReturn.err_msg, 'error');
			    return;
		    }
	    } else {
		    $.loading(false);
		    $.modalAlert("调用医保接口失败", 'error');
		    return;
	    }
	    $.loading(false);
    }
    function YByjsld(ybyjsxx) {
        $.ajax({
            type: "GET",
            url: "/HospitalizationManage/DischargeSettle/subybyjsld",
            data: ybyjsxx,
            dataType: "json",
            async: false,
            success: function (ajaxresp) {
                
            }
        });
    }
    function ovpraseFloat(val) {
	    if (!val) {
		    val = 0;
	    }
	    return parseFloat(val);
    }
</script>